# 堆
import heapq

# 创建堆(最小堆，如果需要最大堆的话，需要每个元素*-1,读取的时候再*-1变回来)
min_heap = []
# 转化为堆
heapq.heapify(min_heap)
# 插入堆
heapq.heappush(min_heap, 10)
heapq.heappush(min_heap, 8)
heapq.heappush(min_heap, 9)
heapq.heappush(min_heap, 2)
heapq.heappush(min_heap, 1)
heapq.heappush(min_heap, 11)
print(min_heap)  # [1, 2, 9, 10, 8, 11]
# 查询
print(min_heap[0])  # 1
# 删除
heapq.heappop(min_heap)
# 长度
print(len(min_heap))  # 5
print(heapq.heapreplace(min_heap, 1))  # 2
